<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.wxName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="电话号">
              <a-input placeholder="请输入电话号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员身份">
              <j-dict-select-tag v-model="queryParam.identity" placeholder="请选择"
                                 dictCode="identity"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="上级用户">
              <j-dict-select-tag v-model="queryParam.onUserId" placeholder="请选择"
                                 dictCode="g_user,wx_name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="身份证号">
              <a-input placeholder="请输入身份证号" v-model="queryParam.idCard"></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="头像">
              <a-input placeholder="请输入头像" v-model="queryParam.wxAvatar"></a-input>
            </a-form-item>
          </a-col>-->
          <!--<template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="openId">
                <a-input placeholder="请输入openId" v-model="queryParam.openId"></a-input>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="上级用户">
                <a-input placeholder="请输入上级用户" v-model="queryParam.onUserId"></a-input>
              </a-form-item>
            </a-col>
            </template>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('会员管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.wxAvatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)">冻结用户</a>-->
          <a-popconfirm title="确定冻结用户吗?" @confirm="() => handleFreeze(record.id)">
            <a v-if="record.delflag == 0">冻结用户</a>
          </a-popconfirm>
          <a-popconfirm title="确定解冻用户吗?" @confirm="() => handleFreeze(record.id)">
            <a v-if="record.delflag == 1">解冻用户</a>
          </a-popconfirm>

          <a-divider type="vertical" />

          <a-popconfirm title="确定授权为代理吗?" @confirm="() => handleEmpower(record.id,'0')">
            <a v-if="record.identity != 0">授权为代理</a>
          </a-popconfirm>

          <a-popconfirm title="确定取消代理吗?" @confirm="() => handleEmpower(record.id,'2')">
            <a v-if="record.identity == 0">取消代理</a>
          </a-popconfirm>

          <a-divider type="vertical" />

          <router-link tag="a" target="_blank"
                       :to="{path:'/givetTicket',query:{userId:record.id}}">赠送门票</router-link>

          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <gameUser-modal ref="modalForm" @ok="modalFormOk"></gameUser-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import GameUserModal from './modules/GameUserModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'

  export default {
    name: 'GameUserList',
    mixins: [JeecgListMixin],
    components: {
      GameUserModal
    },
    data() {
      return {
        description: '会员管理管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '昵称',
            align: 'center',
            dataIndex: 'wxName'
          },
          {
            title: '头像',
            align: 'center',
            dataIndex: 'wxAvatar',
            scopedSlots: {customRender: "avatarslot"}
          },
          /*{
            title: 'openId',
            align: 'center',
            dataIndex: 'openId'
          },*/
          {
            title: '电话',
            align: 'center',
            dataIndex: 'phone'
          },
          {
            title: '真实姓名',
            align: 'center',
            dataIndex: 'realName'
          },
          {
            title: '身份证号',
            align: 'center',
            dataIndex: 'idCard'
          },
          {
            title: '上级用户',
            align: 'center',
            dataIndex: 'onUserId_dictText',
            sorter: true
          },

          {
            title: '支付宝名字',
            align: 'center',
            dataIndex: 'zfbName'
          },
          {
            title: '支付宝账号',
            align: 'center',
            dataIndex: 'zfbNumber'
          },
          {
            title: '身份',
            align: 'center',
            dataIndex: 'identity_dictText'
          },
          {
            title: '平台推广等级',
            align: 'center',
            dataIndex: 'rank_dictText'
          },
          /*{
            title: '0:审核中,1:审核通过(推广员申请)',
            align: 'center',
            dataIndex: 'type'
          },*/
          {
            title: '用户状态',
            align: 'center',
            dataIndex: 'delflag_dictText'
          },

          {
            title: '注册时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: true
          },
          /*{
            title: 'remark',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: 'remark1',
            align: 'center',
            dataIndex: 'remark1'
          },
          {
            title: 'remark2',
            align: 'center',
            dataIndex: 'remark2'
          },
          {
            title: 'remark3',
            align: 'center',
            dataIndex: 'remark3'
          },
          {
            title: 'remark4',
            align: 'center',
            dataIndex: 'remark4'
          },
          {
            title: 'remark5',
            align: 'center',
            dataIndex: 'remark5'
          },
          {
            title: 'remark6',
            align: 'center',
            dataIndex: 'remark6'
          },
          {
            title: 'remark7',
            align: 'center',
            dataIndex: 'remark7'
          },
          {
            title: 'remark8',
            align: 'center',
            dataIndex: 'remark8'
          },
          {
            title: 'remark9',
            align: 'center',
            dataIndex: 'remark9'
          },
          {
            title: 'remark10',
            align: 'center',
            dataIndex: 'remark10'
          },*/
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/gameuser/gameUser/list',
          delete: '/gameuser/gameUser/delete',
          deleteBatch: '/gameuser/gameUser/deleteBatch',
          exportXlsUrl: 'gameuser/gameUser/exportXls',
          importExcelUrl: 'gameuser/gameUser/importExcel',
          freeze:'/gameuser/gameUser/freeze',
          empower:'/gameuser/gameUser/empower',
        }
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {

      getAvatarView: function (wxAvatar) {
        return getFileAccessHttpUrl(wxAvatar)
      },

      //冻结/解冻
      handleFreeze: function (id) {
        if(!this.url.freeze){
          this.$message.error("请设置url.freeze属性!")
          return
        }
        var that = this;
        getAction(that.url.freeze, {id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },

      //授权为代理
      handleEmpower: function (id,identity) {
        if(!this.url.empower){
          this.$message.error("请设置url.fempower属性!")
          return
        }
        var that = this;
        getAction(that.url.empower, {id: id,identity:identity}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>